﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ADOWrapper.ObjectResolver;

namespace ADOWrapper.Test.ObjectResolver
{
    [TestClass]
    public class SimpleConverterTest
    {
        [TestMethod]
        public void Convert()
        {

            Assert.AreEqual(SimpleConverter.Convert<int>(1), 1);
            Assert.AreEqual(SimpleConverter.Convert<int>(null), 0);
            Assert.AreEqual(SimpleConverter.Convert<int>(DBNull.Value), 0);

            Assert.AreEqual(SimpleConverter.Convert<int?>(1), 1);
            Assert.IsNull(SimpleConverter.Convert<int?>(null));
            Assert.IsNull(SimpleConverter.Convert<int?>(DBNull.Value));

        }

        [TestMethod]
        public void ConvertWithIValueResolver()
        {
            Random testValue = new Random();

            Moq.Mock<IValueResolver> resolverMocq = new Moq.Mock<IValueResolver>();
            resolverMocq.Setup<object>((resolver) => resolver.ResolveValue(
                Moq.It.IsAny<int>(),
                Moq.It.IsAny<Type>()
                )).Returns(testValue);

            SimpleConverter.ValueResolvers[typeof(Random)] = resolverMocq.Object;

            Assert.AreEqual(testValue, SimpleConverter.Convert<Random>(1));
            Assert.AreEqual( 1,SimpleConverter.Convert<int?>(1));

          

        }


    }
}
